<?php

// on reprend les smileys de TinyMCE
define('SMILEY_PATH', 'javascript/tiny_mce/plugins/emotions/img/');

$files = glob(SMILEY_PATH.'*.gif');
$SMILEYS = array();
foreach ($files as $path) {
	$name = substr(basename($path), 7);
	$name = substr($name, 0, strrpos($name,'.'));
	$SMILEYS[$name] = $path;
}


function display_bb_tools()
{
	global $SMILEYS;
	?>

    
    
	<div id="forum-write-tools-on">
		<div onclick="javascript:hide_write_tools();" class="forum-button">
			<img  src="images/up.png" alt="-" />
			Masquer les outils de mise en forme
		</div>
		<p>
			Style :
			<input type="button" onclick="insert_tag('[b]', '[/b]');" value="gras" class="forum-txt-bold forum-button" />
			<input type="button" onclick="insert_tag('[i]', '[/i]');" value="italique" class="forum-txt-italic forum-button" />
			<input type="button" onclick="insert_tag('[u]', '[/u]');" value="souligné" class="forum-txt-underline forum-button" />
			<input type="button" onclick="insert_tag('[d]', '[/d]');" value="barré" class="forum-txt-delete forum-button" />
		</p>
		<p>
			Smileys :
		<?php
		foreach ($SMILEYS as $smile => $src)
		{
			echo '<img src="'.$src.'" alt="'.$smile.'" onclick="insert_tag(\' :'.$smile.':\', \'\');" class="forum-button" />&nbsp;';
		}
		?>
		</p>
		<p>
			<input type="button" onclick="insert_tag('[url=http://]', '[/url]');" value="Insérer un lien" class="forum-button" />
			<input type="button" onclick="insert_tag('[img]', '[/img]');" value="Insérer une image" class="forum-button" />
		</p>
    </div>
	
	<div id="forum-write-tools-off">
        <div onclick="javascript:show_write_tools();" class="forum-button">
        	<img src="images/down.png" alt="+" />
            Afficher les outils de mise en forme
        </div>
    </div>

	<?php
	
}


function print_bb_code($content)
{
	global $SMILEYS;
	// remplacement des smileys
	foreach ($SMILEYS as $smile => $src)
	{
		$content = str_replace(':'.$smile.':', '<img src="'.$src.'" alt="'.$smile.'" />&nbsp;', $content);
	}
	
	// remplacement du BB-code
	$bbcode = array(
	'/\[b\](.*?)\[\/b\]/is' => '<span class="forum-txt-bold">$1</span>',
	'/\[i\](.*?)\[\/i\]/is' => '<span class="forum-txt-italic">$1</span>',
	'/\[u\](.*?)\[\/u\]/is' => '<span class="forum-txt-underline">$1</span>',
	'/\[d\](.*?)\[\/d\]/is' => '<span class="forum-txt-delete">$1</span>',
	'/\[url\=(.*?)\](.*?)\[\/url\]/is' => '<a href="$1">$2</a>',
	'/\[img\](.*?)\[\/img\]/is' => '<img src="$1" alt="$1" />'
	
	);
	$content = preg_replace(array_keys($bbcode), array_values($bbcode), $content);
	
	echo nl2br($content);
}

?>

